#default - forked
CFLAGS= -I./include -DUNIX -g -Wall 
LDFLAGS= -g
LDLIBS= -lm -lz
TARGET=run/spdbmp

#uncomment for debugging turn on some debugging info and gprof
#send the parent process SIGUSR2  to quit cleanly
#CFLAGS:= ${CFLAGS} -g -Wall -pg
#LDFLAGS:= ${LDFLAGS} -g -Wall -pg

#for threaded model
thread: CFLAGS:=${CFLAGS} -DTHREADXX
thread: LDLIBS= -lm -lpthread -lz
thread: TARGET:=run/spdbmpt

COMPILER=g++
CPPCOMPILER=g++

SRCFILES =  preproxy.c xsocket.c helpers.c 
SRCFILESPP =  ratehandler.cpp init.cpp logger.cpp rules.cpp cpipes.cpp protocolmanager.cpp
FILTERFILES = connlimsim.cpp limburstsim.cpp ratelimiter.cpp urlfilter.cpp
MYFILES = user/usermodifyheaders.cpp user/userfirewall.cpp
XPROTO = http/protocolhttphandler.cpp http/httphandler.cpp http/headerhandler.cpp http/responsehelper.cpp http/defaultcontenthandler.cpp http/chunkedcontenthandler.cpp http/deflate.c http/mycap.cpp

SRCOBJS=${SRCFILES:.c=.o}
SRCOBJSPP=${SRCFILESPP:.cpp=.o}
FILTEROBJS=${FILTERFILES:.cpp=.o}
MYOBJS=${MYFILES:.c=.o}
PROTOBJS=${PROTOCOLS:.c=.o}

all: common
	yes | cp run/spdbmpt run/were
thread: common
	yes | cp run/spdbmpt run/were

common: ${SRCOBJS:%=objects/%} ${SRCOBJSPP:%=objects/%} ${FILTEROBJS:%=objects/%} 
	$(COMPILER) -o $(TARGET) $(CFLAGS) ${SRCOBJS:%=objects/%} ${SRCOBJSPP:%=objects/%} ${FILTEROBJS:%=objects/%} ${XPROTO:%=protocols/%} $(LDLIBS) 


clean:
	rm -rf objects/*.o filters/*.o $(TARGET)*

upload:	clean
	rm -rf ../upload/kimbula/*
	mkdir -p ../upload/kimbula
	cp  -dR . ../upload/kimbula
	find ../upload -name .svn | xargs rm -rf

	
objects/%.o: src/%.c
	$(CPPCOMPILER)  -o $@ $(CFLAGS) -c $<
objects/%.o: src/%.cpp
	$(CPPCOMPILER)  -o $@ $(CFLAGS) -c $<
objects/%.o: filters/%.cpp
	$(CPPCOMPILER)  -o $@ $(CFLAGS) -c $<
